package com.yq.homework.day22;

import java.io.PrintStream;
import java.util.Random;

/**
 * @author 3307235355@qq.com
 * @since 2022/06/22 20:33
 * 使用穷举法生成长度是3的字符串(000,001,002...999)，
 * 匹配上述生成的密码,将列举到的可能的密码打印,
 * 直到匹配成功结束.
 */
public class Demo06 {
    static Random random = new Random();
    public static void main(String[] args) {
        String s = randomNum(3);
        System.out.println(s);
        for (int i = 0; i < 1000; i++) {
            String format = String.format("%03d", i);
            if (format.equals(s)){
                System.out.println("找到结束"+format);
                break;
            }
        }
    }

    public static String randomNum(int a) {
        String s = "0123456789";
        String s1 = "";
        for (int i = 0; i < a; i++) {
            int r1 = random.nextInt(10);
            s1 += s.charAt(r1);

        }
        return s1;
    }
}
